package com.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author qindengfeng
 * @date 2019/11/8 16:28
 */
@Mapper
@Repository
public interface HelperDao {

    /**
     * 获取当前用户所有表信息
     * @return   List<Map<String,String>>
     */
    @Select("select t.TABLE_NAME tablename,t.COMMENTS  from user_tab_comments t")
    List<Map<String,Object>> getAllTableInfo();

    /**
     * 根据表表获取当前表所有字段信息
     * @param tableName 表名
     * @return List<Map<String,String>>
     */
    @Select("select b.comments ,a.column_name columnname ,a.datatype,b.comments ,'' isKey,a.NULLABLE NULLABLE，data_default datadefault  from\n" +
            "(SELECT  t.COLUMN_NAME,t.DATA_TYPE ||'（'||t.DATA_LENGTH||')' dataType,data_default，\n" +
            "case when t.NULLABLE='Y'then 'N'\n" +
            "     when t.NULLABLE='N' then 'Y' end as NULLABLE\n" +
            "     FROM USER_TAB_COLUMNS t  where t.TABLE_NAME= #{tableName}) a\n" +
            "left join\n" +
            "(SELECT * FROM USER_COL_COMMENTS t1 where t1.TABLE_NAME= #{tableName}) b\n" +
            "on  a.COLUMN_NAME= b.COLUMN_NAME\n" +
            "order by  NULLABLE desc")
    List<Map<String,Object>> getTableFileInfo(String tableName);
}
